package com.shan.xuqiu;

import java.util.Scanner;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
public class MovieService {
    Scanner sc = new Scanner(System.in);
    Movie[] movies;
    

    public MovieService(Movie[] movies) {
        this.movies = movies;
    }

    public void start() {
        go:
        while (true) {
            System.out.println("请输入您的选择：");
            System.out.println("1.查询全部电影信息");
            System.out.println("2.根据id查询电影信息");
            System.out.println("3.退出");
            int choice = sc.nextInt();
            switch(choice){
                case 1:
                    queryMovie();
                    break;
                case 2:
                    queryById();
                    break;
                case 3:
                    System.out.println("退出");
                    break go;
                default:
                    System.out.println("您的输入有误，请认真操作");
                    break;
            }
        }
    }
    private void queryMovie(){
        for (int i = 0; i < movies.length; i++) {
            System.out.println(movies[i].getTitle()+"-------"+movies[i].getScore());
        }
    }
    private void queryById(){
        System.out.println("输入电影id：");
        int num = sc.nextInt();
        for (int i = 0; i < movies.length; i++) {
            if(num==movies[i].getId()){
                System.out.println(movies[i].getId()+"-----"+movies[i].getScore()+"-----"+movies[i].getTitle()+"-----"+movies[i].getArea()+"------"+movies[i].getDirector()+"------"+movies[i].getTime()+"-----"+movies[i].getType());
            }else{
                System.out.println("输入的电影id没有找到");
                break;
            }
        }
    }
}
